package com.yuntongxun.ecdemo.voicechat.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yuntongxun.ecdemo.R;
import com.yuntongxun.ecdemo.voicechat.comman.Transactions;
import com.yuntongxun.ecdemo.voicechat.listeners.IRecyclerViewItemListener;

import java.text.SimpleDateFormat;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Will on 12/9/2015.
 */
public class TransactionsAdapter extends RecyclerView.Adapter {

    private Context mContext;

    private List<Transactions> notes;

    private IRecyclerViewItemListener mListener;

    public TransactionsAdapter(Context context, List<Transactions> noteList, IRecyclerViewItemListener myItemClickListener) {

        mContext = context;

        this.notes = noteList;

        mListener = myItemClickListener;
    }

    @Override
    public int getItemCount() {
        return notes.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int type) {
        View v = View.inflate(viewGroup.getContext(), R.layout.adapter_transactions_list_item, null);

        return new HomeFragmentViewHolder(v);
    }

    @Override
    public int getItemViewType(int position) {
        return position % 4;  //any logic can go here
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

        HomeFragmentViewHolder holder = (HomeFragmentViewHolder) viewHolder;

        Transactions transactions = notes.get(position);

        holder.transactionsNameTv.setText(transactions.getModel() + "");

        SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String d = format.format(notes.get(position).getCreateTime());
        holder.transactionsTimeTv.setText(d);

        holder.balanceNumTv.setText("balance:" + transactions.getBalance());
        holder.moneyAmountTv.setText(transactions.getType() + transactions.getAmount());
    }

    public class HomeFragmentViewHolder extends RecyclerView.ViewHolder {

        @InjectView(R.id.transactions_name_tv)
        TextView transactionsNameTv;
        @InjectView(R.id.transactions_time_tv)
        TextView transactionsTimeTv;
        @InjectView(R.id.balance_num_tv)
        TextView balanceNumTv;
        @InjectView(R.id.money_amount_tv)
        TextView moneyAmountTv;

        public HomeFragmentViewHolder(View itemView) {
            super(itemView);

            ButterKnife.inject(this, itemView);
        }

    }

}
